//
// Created by sjjmw on 3/24/2022.
//
#include "iostream"
#include "vector"
#include "list"
#include "algorithm"
#include "string"

//窗口暴力sub即可
void handle(std::string &a,std::string&b
            ){
    std::vector<std::string> strs;
    if(a.size()>b.size()){
        std::swap(a,b);
    }
    for(int i=a.size();i>0;i--){
        for(int off=0;off<=a.size()-i;off++){
            std::string sub=a.substr(off,i);
            if(b.find(sub)!=-1){
                strs.push_back(sub);
            }
        }
        if(strs.size()>0){
            break;
        }
    }
    if(strs.size()==0){
        printf("\n");
    }else{
        std::sort(strs.begin(),strs.end());
        std::cout<<strs[0]<<std::endl;
    }

}

int main(){
    int a,b;
    std::string str1,str2;
    while(std::getline(std::cin,str1)){
        std::getline(std::cin,str2);
        handle(str1,str2);
    }
    return 0;
}